package com.qingmeng.applyjob.portal.controller;

import com.qingmeng.applyjob.common.api.CommonPage;
import com.qingmeng.applyjob.common.api.CommonResult;
import com.qingmeng.applyjob.portal.model.dto.*;
import com.qingmeng.applyjob.portal.model.vo.CoachListVo;
import com.qingmeng.applyjob.portal.model.vo.CoachingRecordListVo;
import com.qingmeng.applyjob.portal.model.vo.MyCoachListVo;
import com.qingmeng.applyjob.portal.model.vo.TeacherVo;
import com.qingmeng.applyjob.portal.service.CoachService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/coach")
@Api(tags = "coachController" , description = "辅导接口")
public class CoachController {

    @Autowired
    private CoachService coachService;

    @ApiOperation("填写教师信息")
    @PostMapping("/improveTeacherInformation")
    private CommonResult<Integer> improverTeacherInformation(@ApiParam("需要填写的信息") @RequestBody ImproveTeacherInformationParam improveTeacherInformationParam){
        int result = coachService.improveTeacherInformation(improveTeacherInformationParam);
        if (result > 0){
            return CommonResult.success(result,"填写教师信息完成");
        }
        return CommonResult.failed("教师信息填写失败");
    }

    @ApiOperation("发布辅导")
    @PostMapping("/publishCoach")
    private CommonResult<Integer> publishCoach(@ApiParam("发布辅导时需要填写的信息") @RequestBody CoachPublishParam coachPublishParam){
        int result = coachService.publishCoach(coachPublishParam);
        if (result > 0){
            return CommonResult.success(result,"辅导发布成功");
        }
        return CommonResult.failed("辅导发布失败");
    }

    @ApiOperation("获取教师相关信息")
    @GetMapping(value = "/teacherInformation")
    public CommonResult<TeacherVo> list(@ApiParam("教师id") @RequestParam(value = "teacherId") Long teacherId,
                                                      @ApiParam("辅导id") @RequestParam(value = "coachId") Long coachId){
        TeacherVo teacherVo = coachService.teacherInformation(teacherId , coachId);
        if (teacherVo != null){
            return CommonResult.success(teacherVo,"获取教师信息成功");
        }
        return CommonResult.failed("没有查询到教师相关数据");
    }

    @ApiOperation("获取辅导列表")
    @GetMapping(value = "/coachList")
    public CommonResult<CommonPage<CoachListVo>> coachList(@ApiParam("页码") @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                      @ApiParam("每页包含的条数") @RequestParam(value = "pageSize" , defaultValue = "2") Integer pageSize){
        List<CoachListVo> coachListVoList = coachService.coachList(pageNum, pageSize);
        if (coachListVoList != null && coachListVoList.size() > 0){
            return CommonResult.success(CommonPage.restPage(coachListVoList),"获取成功");
        }
        return CommonResult.failed("没有查询到相关数据");
    }

    @ApiOperation("预约辅导")
    @PostMapping("/leaveMessage")
    private CommonResult<Integer> leaveMessage(@ApiParam("预约辅导时需要填写的信息") @RequestBody LeaveMessageParam leaveMessageParam){
        int result = coachService.leaveMessage(leaveMessageParam);
        if (result > 0){
            return CommonResult.success(result,"辅导预约成功");
        }
        return CommonResult.failed("辅导预约失败");
    }

    @ApiOperation("发布评论")
    @PostMapping("/postComment")
    private CommonResult<Integer> postComment(@ApiParam("发布评论时需要填写的信息") @RequestBody CommentPublishParam commentPublishParam){
        int result = coachService.postComment(commentPublishParam);
        if (result > 0){
            return CommonResult.success(result,"评论发布成功");
        }
        return CommonResult.failed("评论发布失败");
    }

    @ApiOperation("回复评论")
    @PostMapping("/postReply")
    private CommonResult<Integer> postReply(@ApiParam("回复评论时需要填写的信息") @RequestBody ReplyPublishParam replyPublishParam){
        int result = coachService.postReply(replyPublishParam);
        if (result > 0){
            return CommonResult.success(result,"评论回复成功");
        }
        return CommonResult.failed("评论回复失败");
    }

    @ApiOperation("获取导师辅导记录(flag 控制排序顺序 0为数据库顺序 1为按价格顺序排列 ， 2为按价格逆序排列 ， 3为按时间顺序排列 ， 4为按时间逆序排列)")
    @GetMapping("/coachingRecords")
    private CommonResult<CoachingRecordListVo> coachingRecords(@ApiParam("页码") @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                           @ApiParam("每页包含的条数") @RequestParam(value = "pageSize", defaultValue = "2") Integer pageSize,
                                                                           @ApiParam("想要获取的老师的ID号") @RequestParam(value = "teacherId") Long teacherId,
                                                                           @ApiParam("选择排序方式") @RequestParam(value = "flag") int flag ){
        CoachingRecordListVo coachingRecordListVo = coachService.coachingRecords(pageNum, pageSize, teacherId, flag);
        CommonPage.restPage(coachingRecordListVo.getRecordsList());
        if (coachingRecordListVo != null){
            return CommonResult.success(coachingRecordListVo,"获取辅导记录成功");
        }
        return CommonResult.failed("没有查询到相关记录");
    }

    @ApiOperation("获取我的未认证的辅导列表")
    @GetMapping(value = "/getMyNotCertificatedCoachList")
    public CommonResult<CommonPage<MyCoachListVo>> getMyNotCertificatedCoachList(@ApiParam("页码") @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                           @ApiParam("每页包含的条数") @RequestParam(value = "pageSize" , defaultValue = "2") Integer pageSize){
        List<MyCoachListVo> coachListVoList = coachService.getMyNotCertificatedCoachList(pageNum, pageSize);
        if (coachListVoList != null && coachListVoList.size() > 0){
            return CommonResult.success(CommonPage.restPage(coachListVoList),"获取成功");
        }
        return CommonResult.failed("没有查询到相关数据");
    }

}
